package controller

import (
	"fx_swift_ifcgate_agent/api"
	"fx_swift_ifcgate_agent/internal/service"
	"fx_swift_ifcgate_agent/pkg/code"
	"fx_swift_ifcgate_agent/pkg/internalerrors"
	"github.com/gin-gonic/gin"
	"net/http"
)

// 新增手续费配置
func CreateEnterpriseFee(c *gin.Context) {
	req := &api.FeeReq{}
	if err := c.ShouldBindJSON(&req); err != nil {
		code.Fail(c, http.StatusBadRequest, code.ErrEncodingJSON, err.(internalerrors.ServiceError).Msg)
		return
	}

	err := service.NewFeeSrv().CreateEnterpriseFee(c, req)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, nil)
	}
}

// 查询手续费详情
func QueryEnterpriseFeeDetails(c *gin.Context) {
	enterpriseAccount := c.Query("account")
	merchantNo := c.Query("merchantNo")

	result, err := service.NewFeeSrv().QueryEnterpriseFeeDetails(c, enterpriseAccount, merchantNo)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

// 查询上级手续费详情
func GetParentFeeDetails(c *gin.Context) {
	result, err := service.NewFeeSrv().GetParentFeeDetails(c)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}
